<?php
class settingController extends accessController{
    public static function _right(){
        return array(
            array('网站管理',1),
            array('变量添加','add,add_'),
            array('变量列表','mylist'),
            array('变量编辑','mod,mod_'),
            array('变量删除','del'),
            array('变量生成','update'),
        );
    }
	public function s(){
		return array('setting');
	}
	public function update(){
		$r=$this->s_0->update();
		if($r){
			alert('更新成功！');
		}else{
			alert('更新失败！');
		}
		back();
	}
	public function add(){
		$mysort=time();
		include($this->viewer_dir.'setting/add.php');
	}
	public function add_(){
    	if($_POST){
			$r=$this->s_0->add_($_POST);
			autoalert($r[0],$r[1]);
			back();
        }
    }
	public function mylist(){
	    
		$condition=array();
		$extra='';
		$extra_data=array();
		
		$id=intval($_GET['id']);//
		$id=$id==0?'':$id;
		if($id){
			$condition['id']=$id;
			$extra.=" and `id`=:id";
			$extra_data['id']=$id;
		}
		
		$varname=trim($_GET['varname']);//
		if($varname){
			$condition['varname']=$varname;
			$extra.=" and `varname` like :varname";
			$extra_data['varname']="%{$varname}%";
		}
		$note=trim($_GET['note']);//
		if($note){
			$condition['note']=$note;
			$extra.=" and `note` like :note";
			$extra_data['note']="%{$note}%";
		}
		
	    $return=$this->s_0->li($condition,$extra,$extra_data);
		include($this->viewer_dir.'setting/mylist.php');
	}
	public function mod(){
        $id=intval($_GET['id']);
        if($id>0){
            $data=$this->s_0->mod($id);
            if($data){
                include($this->viewer_dir.'setting/mod.php');
            }
        }
    }
    public function mod_(){
		$id=intval($_GET['id']);
        if($_POST and $id>0){
            $r=$this->s_0->mod_($_POST,$id);
            autoalert($r[0],$r[1]);
            back();
        }
    }
	public function del(){
		$id=intval($_GET['id']);
        if($id>0){
            $r=$this->s_0->del($id);
            autoalert($r[0],$r[1]);
            back();
        }
	}
//
}